import httpx


def get_comment(url, headers, cookies, json_data):

    with httpx.Client() as client:
        response = client.post(url, headers=headers, cookies=cookies, json=json_data)
        return response.json()


def parse_comment(comment):
    root_comments = comment['data']['visionCommentList']['rootComments']
    for item in root_comments:
        print(item['content'])


def main():
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
    }
    cookies = {
        "kpf": "PC_WEB",
        "clientid": "3",
        "did": "web_717ad7a5d13c8afb38e63e8aacaf6e7f",
        "userId": "3498836671",
        "kuaishou.server.web_st": "ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABFsGQq0_BYdyIXKzAAEdcn89-R4PZ5EL1Bcmie5bHwkrQG48YktDMw2fnlh-I1IHZmEC763nZHWEag4YErr7U-8bNfU9R4HFTzfp2BaMYRyb3tOBBiEtft-vX8zTbb0Q-K3Ke85ZctyIwquY3xyDBGiG4HFQRw7aWiAKyoOsMGk12gas53cvyVEgbsFf8dkbodcn5862OCsp45SRGH3fWTxoSsmhEcimAl3NtJGybSc8y6sdlIiBBNMRslUAl6JcK35b-wZaUK68_vE35Vc_Vq2NgOCuRWigFMAE",
        "kuaishou.server.web_ph": "4058b1cbb772546dbb25b4078b39c4495bb6",
        "kpn": "KUAISHOU_VISION"
    }
    url = "https://www.kuaishou.com/graphql"
    json_data = {
        "operationName": "commentListQuery",
        "variables": {
            "photoId": "3xueudrc4ka8gbw",
            "pcursor": ""
        },
        "query": "query commentListQuery($photoId: String, $pcursor: String) {\n  visionCommentList(photoId: $photoId, pcursor: $pcursor) {\n    commentCount\n    pcursor\n    rootComments {\n      commentId\n      authorId\n      authorName\n      content\n      headurl\n      timestamp\n      likedCount\n      realLikedCount\n      liked\n      status\n      authorLiked\n      subCommentCount\n      subCommentsPcursor\n      subComments {\n        commentId\n        authorId\n        authorName\n        content\n        headurl\n        timestamp\n        likedCount\n        realLikedCount\n        liked\n        status\n        authorLiked\n        replyToUserName\n        replyTo\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n"
    }
    comment = get_comment(url, headers, cookies, json_data)
    parse_comment(comment)


if __name__ == '__main__':
    main()
